/***************************************************************************************************************
This File is under GNU License
 * Kshampoo

 **************************************************************************************************************/
import com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.net.URL;
import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.io.*; 
//import statements
//Check if window closes automatically. Otherwise add suitable code
public class Main extends JPanel implements ActionListener {

	JLabel jlbLabel1, jlbLabel2,jlbLabel3,emptyLabel,emptyLabel2,emptyLabel3,jlbLabelResult,jlbLabelConfirm;
        
        protected static JButton jbnLeft, jbnMiddle, jbnRight;
	       
	public Main() {
            String imageURL = "D:\\Program Files\\Java\\jre1.6.0_04\\lib\\images\\kshampoo\\banner_image.JPG";
                
		ImageIcon icon = new ImageIcon(imageURL,"KShampoo");
		// Creating an Icon
		                
                jlbLabel1 = new JLabel("Try All new KShampoo");
               
		// We can position of the text, relative to the icon:
                jlbLabel1.setVerticalTextPosition(JLabel.TOP);
		jlbLabel1.setHorizontalTextPosition(JLabel.LEFT);
                
                emptyLabel = new JLabel("                ");
                emptyLabel.setSize(200,200);
                
                emptyLabel2 = new JLabel("                 ");
                emptyLabel2.setSize(200,200);
                
                emptyLabel3 = new JLabel("                    ");
                emptyLabel3.setSize(200,200);
                                
                jlbLabel2 = new JLabel(icon, JLabel.CENTER);
                
                // We can position of the text, relative to the icon:
		jlbLabel2.setVerticalTextPosition(JLabel.TOP);
		jlbLabel2.setHorizontalTextPosition(JLabel.LEFT);
                
		jlbLabel3 = new JLabel("Choose options");
		
                // We can position of the text, relative to the icon:
		jlbLabel3.setVerticalTextPosition(JLabel.BOTTOM);
		jlbLabel3.setHorizontalTextPosition(JLabel.LEFT);
                
		// Add labels to the Panel
		add(jlbLabel1);
                add(emptyLabel);                                            
		add(jlbLabel2);
                add(emptyLabel2);
                add(emptyLabel3);               
                add(jlbLabel3);	
                           
                // Create Icons that can be used with the jButtons
		//ImageIcon leftButtonIcon = createImageIcon("E:\\Java Projects\\kshampoo\\src\\kshampoo\\button_image.JPG");
		//ImageIcon middleButtonIcon = createImageIcon("E:\\Java Projects\\kshampoo\\src\\kshampoo\\button_image.JPG");
		//ImageIcon rightButtonIcon = createImageIcon("E:\\Java Projects\\kshampoo\\src\\kshampoo\\button_image.JPG");
      
		jbnLeft = new JButton("Run Screen Saver");
                jbnLeft.setSize(20,30);
		jbnLeft.setVerticalTextPosition(AbstractButton.CENTER);
		jbnLeft.setHorizontalTextPosition(AbstractButton.CENTER);
		jbnLeft.setMnemonic(KeyEvent.VK_D);
                
		// Alt-D clicks the button
		jbnLeft.setActionCommand("Clean");
		jbnLeft.setToolTipText("Run Screen Saver."); // Adding Tool
									// tips
		jbnMiddle = new JButton("Refresh the Screen");
                jbnMiddle.setSize(20,30);
		jbnMiddle.setVerticalTextPosition(AbstractButton.BOTTOM);
		jbnMiddle.setHorizontalTextPosition(AbstractButton.CENTER);
		jbnMiddle.setMnemonic(KeyEvent.VK_M);
                
		// Alt-M clicks the button
                jbnMiddle.setActionCommand("Refresh");
		jbnMiddle.setToolTipText("Refresh the Screen.");   
                
                
		jbnRight = new JButton("Visit Our Project Site");
                jbnRight.setSize(20,30);
		// Use the default text position of CENTER, TRAILING (RIGHT).
		jbnRight.setMnemonic(KeyEvent.VK_E);
		
                // Alt-E clicks the button
		jbnRight.setActionCommand("Special");
		jbnRight.setToolTipText("Visit Our Project Site.");
		// Disable the Button at creation time
                
                // Set the Size of Left and Right Buttons
		jbnLeft.setSize(new Dimension(5,5));
		jbnMiddle.setSize(new Dimension(5,5));
		jbnRight.setSize(new Dimension(5,5));          
                
		// Listen for actions on Left and Roght Buttons
		jbnLeft.addActionListener(this);
		jbnMiddle.addActionListener(this);
		jbnRight.addActionListener(this);
		// Add Components to the frame, using the default FlowLayout.
		add(jbnLeft);
		add(jbnMiddle);
		add(jbnRight);
	}
	public void actionPerformed(ActionEvent e) {
		if ("Refresh".equals(e.getActionCommand())) {                
                   try 
                    { 
                        Process p=Runtime.getRuntime().exec("cmd /c RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters"); 
//                        p.waitFor(); 
//                        BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
//                        String line=reader.readLine(); 
//                        while(line!=null) 
//                        { 
//                        System.out.println(line); 
//                        line=reader.readLine(); 
//                        } 
                    } 
                    catch(IOException e1) {} 
//                    catch(InterruptedException e2) {} 
                   // System.out.println("Done"); 
		} 
                else if ("Special".equals(e.getActionCommand())) {
                  try 
                    { 
Process p=Runtime.getRuntime().exec("cmd /c rundll32.exe url.dll,FileProtocolHandler http://code.google.com/p/kshampoo/"); 
//                        p.waitFor(); 
//                        BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
//                        String line=reader.readLine(); 
//                        while(line!=null) 
//                        { 
//                        System.out.println(line); 
//                        line=reader.readLine(); 
//                        } 
                    } 
                    catch(IOException e1) {} 
//                    catch(InterruptedException e2) {}    
                   
			
		}
                else if ("Clean".equals(e.getActionCommand())) {
                    try 
                    {                                 
                              
Process p=Runtime.getRuntime().exec("cmd /c ssflwbox.scr /s");
Process p1=Runtime.getRuntime().exec("cmd /c RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters");
//                        p.waitFor(); 
//                        BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
//                        String line=reader.readLine(); 
//                        while(line!=null) 
//                        { 
//                        System.out.println(line); 
//                        line=reader.readLine(); 
//                        } 
                    } 
                    catch(IOException e1) {
                    System.err.println("Error: " + e1.getMessage());
                    
                    } 
//                    catch(InterruptedException e2) {}	
		}
	}
	// Returns an ImageIcon, or null if the path was invalid.
	protected static ImageIcon createImageIcon(String path) {
		URL imgURL = Main.class.getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL);
		} else {
			System.err.println("Couldn't find image in system: " + path);
			return null;
		}
	}
	// Create the GUI and show it.
	private static void createGUI() {                
                // Create and set up the frame.
  JFrame frame = new JFrame("KShampoo::Screen Saver");
  String imgURL = "D:\\Program Files\\Java\\jre1.6.0_04\\lib\\images\\kshampoo\\banner_image.JPG";
  frame.setIconImage(new ImageIcon(imgURL).getImage());
  
		frame.addWindowListener(new WindowAdapter() {

			// Shows code to Add Window Listener
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
                
                // Create and set up the content pane.
		Main buttonContentPane = new Main();
		buttonContentPane.setOpaque(true); // content panes must be opaque
                frame.setLayout(new BorderLayout());
		frame.getRootPane().setDefaultButton(jbnLeft);
                frame.setSize(new Dimension(320,320));
                frame.setPreferredSize(new Dimension(320,320));
                //frame.setMaximumSize(new Dimension(300,300));
               // frame.setMinimumSize(new Dimension(300,300));
                frame.setResizable(false);
                
		//frame.getContentPane().add(frame, BorderLayout.CENTER);
                frame.setContentPane(buttonContentPane);
                frame.setContentPane(new Main());
                
                frame.setDefaultLookAndFeelDecorated(true);		
		frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
                
		// Display the window.
		frame.pack();
		frame.setVisible(true);		
	}        
        
        
	public static void main(String[] args) {               
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createGUI();
			}
		});	
	}

  

}